//车辆诚信记录

interface CarCommentManagent extends ng.IScope{
    /**
     * 车牌号
     */
    carCode:string;
    /**
     * 评价人
     */
    appraiser:string;
    /**
     * 诚信度
     */
    credibility:string;
    /**
     * 时效性
     */
    timeliness:string;
    /**
     * 服务态度
     */
    attitude:string;
    /**
     * 运输价格
     */
    freight:string;
    /**
     * 总分
     */
    average:string;
    /**
     * 评价时间
     */
    creationTime:string;
    /**
     * 评价内容
     */
    content:string;
    /**
     * 是否好评
     */
    isPraise:string
    appraiserid:string;

    total:number;
    /**
     * 总分
     */
    evaluateList:Array<EvaluateListItemResponse>;
    
    praiseCount:number;
    totalItems:number;
    currentPage:number;
    max:number;
    /**
     * 分页事件
     */
    pageChanged:(page:number)=>void;
    
}



class CarEvaluateManagentController {
    isReadonly:boolean = true;  
    driveruserId:string;

    constructor( private $scope:CarCommentManagent,private carService:ICarService,private valueService:IValueService ,private $ngBootbox: BootboxService, private $location: ng.ILocationService ){
        this.init();
    }

    init():void{
        this.$scope.max=5;        
        this.$scope.currentPage = 1;
        this.$scope.totalItems = 5;

        //this.$scope.average = this.$location.search().average;
        this.$scope.average = JSON.parse(window.localStorage.getItem("car").toString()).average;

        //this.$scope.carCode = JSON.parse(window.localStorage.getItem("car").toString()).carCode;
        this.driveruserId = JSON.parse(window.localStorage.getItem("car").toString()).carId;
        //this.$scope.praiseCount = this.$location.search().praiseCount;
        this.$scope.praiseCount = JSON.parse(window.localStorage.getItem("car").toString()).praiseCount;

        this.loadData(this.driveruserId,"","",0,5);
        this.$scope.pageChanged = this.pageChanged;
    }

    /**
     * 加载
     */
    loadData(driveruserId,carCode,appraiserid,skip:number,count:number):void{
        this.carService.getEvaluateList(this.driveruserId,"","",skip,count).then((res)=>{
            res.data.data.map((item,index)=>{item.index = (skip * 10) + (index + 1)});
            this.$scope.total = res.data.total;
            this.$scope.evaluateList = res.data.data;
            this.$scope.totalItems= res.data.total;

            this.$scope.evaluateList.forEach(item=>{
                item['credibilityStar']=item.credibility/2;
                item['attitudeStar']=item.attitude/2;
                item['timelinessStar']=item.timeliness/2;
                item['freightStar']=item.freight/2;
                //平均分
                item['averageStar'] = item.average/2;
            })
        });
    }

    /**
     * 分页  page:number
     */
    pageChanged=(page:number)=>{
        var currentPage = (page - 1 )*this.$scope.max;
        this.loadData(this.driveruserId,"", "", currentPage ,5);
    }

}


angular.module("tms").controller("carEvaluateManagentController", ["$scope", "carService" , "valueService" , "$ngBootbox","$location",CarEvaluateManagentController]);

